package pers.cz.selenium.core;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @program: PostGirl-panent
 * @description: 谷歌驱动工厂
 * @author: Cheng Zhi
 * @create: 2022-12-24 20:35
 **/
@Component
public class SeleniumChromeFactory implements SeleniumFactory {

    //@Value("${selenium.chrome.driverPath}")
    private String driverPath = "D:\\python\\chromedriver_win32\\chromedriver.exe";

    private ChromeDriver chromeDriver;
    @Override
    public ChromeDriver createWebDriver() {

        if (chromeDriver == null) {
            System.getProperties().setProperty("webdriver.chrome.driver", driverPath);
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeDriver = new ChromeDriver(chromeOptions);
        }

        return chromeDriver;
    }
}
